<template>
	<view class="">
		<view class="my-list">
			<!-- :height="swiperHeight" -->
			<u-list @scrolltolower="scrolltolower" v-if="dataList.length > 0">
				<u-list-item v-for="(proIm, proIx) in dataList" :key="proIm.id">
					<view 
						class="gift-bag-item" 
						:style="{background: proIm.bgColor}"
					>
						<view class="flex flex--row">
							<text>{{proIm.name}}</text>
							<text class="fsize-24 mt-10">含{{proIm.projectCount}}种项目 · 共{{proIm.quantityAll}}</text>
							<text class="fsize-24 mt-10">￥{{proIm.salePrice}}</text>
						</view>
						<view class="flex justify-between">
							<text class="fsize-24">使用期限{{proIm.validDays}}天</text>
							<view class="flex justify-end">
								<view class="obtn" v-if="userInfo.roleCategoryId===2" @click="onShare(proIm.id, proIm.shareCode, 14)">分享</view>
								<view class="obtn" v-if="userInfo.roleCategoryId===3 || userInfo.roleCategoryId === 5" @click="onDel(proIx)">删除</view>
								<view class="obtn" v-if="userInfo.roleCategoryId===3 || userInfo.roleCategoryId === 5" @click="$u.route('/pages/project/card/edit',{id:proIm.id})">编辑</view>
							</view>
						</view>
					</view>
				</u-list-item>
				<u-loadmore 
					:status="loadmore.status" 
					:icon-type="loadmore.iconType"
					:load-text="loadmore.loadText.loadText" 
					margin-top="20" 
					margin-bottom="20"
				/>
			</u-list>
		</view>
		<!-- 无数据时默认显示 -->
		<view class="emptybox" v-if="dataList.length == 0">
			<u-empty icon-size="150" text="暂无数据" mode="data"></u-empty>
		</view>
		<uni-fab 
			v-if="userInfo.roleCategoryId === 3 || userInfo.roleCategoryId === 5"
			:popMenu="false" 
			ref="fab" 
			horizontal="right" 
			:pattern="pattern"
			@fabClick="$u.route('/pages/project/card/edit')"
		/>
	</view>
</template>

<script>
	import listHeightMixin from '@/common/computedAltitude.js'
	import share from '@/common/mixins/share.js'
	import { mapState } from 'vuex'
	export default {
		mixins:[listHeightMixin, share],
		data() {
			return {
				loadmore: {
					status: 'loadmore',
					iconType: 'flower',
					loadText: {
						loadmore: '轻轻上拉',
						loading: '努力加载中',
						nomore: '实在没有了'
					},
				},
				dataList: [],
				searchData: {
					page: 1,
					limit: 10,
					share:1,
				},
				pattern: { buttonColor :'#e54d42' }
			}
		},
		onLoad() {
			this.initData()
			uni.$on('upCardList', ()=>{
				this.initData()
			})
		},
		onUnload(){
			uni.$off('upCardList')
		},
		computed: {
			...mapState(['userInfo'])
		},
		methods: {
			initData(){
				this.searchData.page = 1
				this.dataList = []
				this.getPageList()
			},
			onDel(ix) {
				let that = this
				uni.showModal({
					title: '提示',
					content: `确定要删除${that.dataList[ix].name}吗?`,
					success: function(res) {
						if (res.confirm) {
							that.$reqJsonPost('ProjectCategoryDoDelete', { id: that.dataList[ix].id }).then(res => {
								if (res.code === 0) {
									that.dataList.splice(ix, 1)
								}
							})
						}
					}
				})
			},
			getPageList() {
				this.$reqPost('ProjectCategoryCardItemList', this.searchData).then(res => {
					this.dataList = [...this.dataList, ...res.data]
					if (res.count > this.dataList.length) {
						this.loadmore.status = 'loadmore'
						this.searchData.page++
					} else {
						// 数据已加载完毕
						this.loadmore.status = 'nomore'
					}
				})
			},
			scrolltolower() {
				if (this.loadmore.status === 'loadmore') {
					this.getPageList()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	
</style>
